package com.springboot.last_experiment.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.springboot.last_experiment.entity.Health;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface HealthDao extends BaseMapper<Health> {
    @Options(useGeneratedKeys = true,keyProperty = "healthId")
    @Insert("insert into health " +
            "(openid,temperature,status,is_contact,is_arrive,time,access) " +
            " values (#{openid},#{temperature},#{status},#{isContact},#{isArrive},#{time},#{access})")
    public void insertHea(Health health);

    @Select("select * from health")
    public List<Health> getAllHea();

    @Select(value = "select * from health where health_id=#{id}")
    public Health getHeaById(Integer id);

    @Select("select * from health where " +
            " (access=#{key} and not #{flag} )" +
            " or (status=#{key} and #{flag})")
    public List<Health> getHeaByKey(String key, boolean flag);

    @Update("update health set " +
            "temperature=#{temperature}," +
            "status=#{status}," +
            "is_contact=#{isContact}," +
            "is_arrive=#{isArrive}," +
            "access=#{access}," +
            "time=#{time} where health_id=#{healthId}")
    public void updateHea(Health health);


    @Select(value = "select * from health where openid=#{id} and datediff(NOW(), time) <= 14")
    public List<Health> getHeaByOpenid(String id);


}
